import statistics
import matplotlib.pyplot as plt
import numpy as np

filename = 'single-link-up1.log'
x = []
for line in open(filename):
    x.append((float(line.split(', ')[1]) - float(line.split(', ')[0]))/1000000)
# x = x[1:]

print min(x)
print max(x)
print statistics.mean(x)
print statistics.median(x)

n = np.arange(1, len(x) + 1) / np.float(len(x))
Xs = np.sort(x)

# plt.figure()
fig, ax = plt.subplots(figsize=(6, 4))
ax.step(Xs, n)

ax.grid(True)
# ax.legend(loc='right')
ax.set_title('CDF ospf %s' % filename)
ax.set_xlabel('Time(ms)')
plt.savefig('%s.png' % filename)
plt.show()